//
//  FindVC.swift
//  JTYP
//
//  Created by Groot on 2017/12/13.
//  Copyright © 2017年 inspur. All rights reserved.
//

class FindVC: TransparentNavBarVC {
    
    let scrollBarItems = [ScrollBarItem.init(itemName: "悦通知"),
                          ScrollBarItem.init(itemName: "悦剪辑"),
                          ScrollBarItem.init(itemName: "悦健康")]
    let noticeTypes = [NoticeType.nomal,
                      NoticeType.edit,
                      NoticeType.health]

    private var scrollbarView: ScrollBarView = {
        var v = ScrollBarView()
        return v
    }()
    private var topView: CustomTopView = {
        var v: CustomTopView = Bundle.main.loadNibNamed("CustomTopView", owner: nil, options: nil)?.first as! CustomTopView
        return v
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        statusBarShouldLight = false

        if #available(iOS 11.0, *) {
            self.scrollbarView.scrollBar.contentInsetAdjustmentBehavior = .never;
        }else {
            self.automaticallyAdjustsScrollViewInsets = false;
        }
        setupScrollBarView()
    }
    
    func setupScrollBarView() {
        
        var vcs: [BaseCollectionVC] = []
        
        for i in 0 ..< scrollBarItems.count {

            guard noticeTypes[i] != .edit else{
                vcs.append(FindFlexibleVC.init(collectionViewLayout: UICollectionViewLayout()))
                continue
            }
            
            let layout = UICollectionViewFlowLayout()
            //layout.scrollDirection = .vertical
            layout.minimumLineSpacing = 0
            layout.minimumInteritemSpacing = 0
            layout.footerReferenceSize = .zero

            let vc = FindCollectionVC.init(collectionViewLayout: layout, type: noticeTypes[i])
            vcs.append(vc)
        }
        
        // viewcontrollers
        view.addSubview(scrollbarView)
        scrollbarView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.top.equalToSuperview().offset(25)
        }
        scrollbarView.layoutIfNeeded()
        scrollbarView.normalTitleColor = .darkGray
        scrollbarView.selectedTitleColor = DefaultColor.green
        scrollbarView.scrollBarTitleFontSize = 17.0
        scrollbarView.bottomLineColor = UIColor.init(white: 0.8, alpha: 0.7)
        scrollbarView.backgroundColor = .clear
        scrollbarView.setScrollBarItems(items: scrollBarItems, and: vcs, style: .average)
        scrollbarView.scrollBar.backgroundColor = .clear
        scrollbarView.updateScrollBarConstraints()
    }
    
}
